package com.bjpowernode.crm.common.entity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

/**
 * 公共返回值实体类
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
public class BaseResult<T> {

    private Integer code;
    private boolean success;
    private String msg;
    private T data;

    // 转换为json和返回的map是一致的
    public BaseResult ok(){
        return new BaseResult(20000,true,"请求成功",null);
    }

    public BaseResult ok(Integer code,String msg){
        return new BaseResult(code,true,msg,null);
    }

    public BaseResult ok(Integer code,String msg,T data){
        return new BaseResult(code,true,msg,data);
    }

    public BaseResult ok(Integer code,boolean success,String msg,T data){
        return new BaseResult(code,success,msg,data);
    }

    public BaseResult err(Integer code,String msg){
        return new BaseResult(code,false,msg,null);
    }
}
